package com.xmgps.bdt.infrastructure.util;

import io.netty.buffer.ByteBuf;

/**
 * zeno
 * 2022/6/20
 */
public class BcdUtil {

    /**
     * BCD 二进制值转换成字符串
     *
     * @param src
     * @param length
     * @return
     */
    public static String convertToString(ByteBuf src, int length){

        byte value;
        StringBuilder sb = new StringBuilder(length * 2);
        for (int i = 0; i<length; ++i){
            value = src.readByte();
            sb.append((value&0xF0) >> 4).append(value&0x0F);
        }

        return sb.toString();
    }
}
